<template>
    <div class="login-wrap"  v-loading="loading"
    element-loading-text="拼命登录中"
    element-loading-spinner="el-icon-loading"
    element-loading-background="rgba(0, 0, 0, 0.8)">
        <div class="header">
            <div class="top">
                <div class="logo">
                    <img src="../../assets/img/logo_login.png" width="350" />
                </div>
                <div class="navbox">
                    <a href="app.html" id="qrcodeShow" target>
                        APP下载
                        <img
                            src="../../assets/img/app.png"
                            style="border:none; outline:none; vertical-align:middle; margin-left:3px; margin-top:-5px;"
                        />
                    </a>
                    <img
                        style="position: absolute; top: 70px; left: 50%; margin-left: 260px; box-shadow: rgba(0, 0, 0, 0.2) 0px 2px 4px; border: 1px solid rgb(228, 228, 228); width: 150px; background: rgb(255, 255, 255); padding: 5px; display: none;"
                        id="qrcode"
                        src="images/qrcode.png"
                    />
                </div>
            </div>
        </div>
        <form id="form1">
            <div class="loginBox">
                <div class="loginbox_bg">
                    <div class="loginBox_left">
                        <img src="../../assets/img/tex.png" style=" padding-top:20px;" />
                    </div>
                    <div class="ms-login">
                        <div class="ms-title">用户登录</div>
                        <el-form
                            :model="param"
                            :rules="rules"
                            ref="login"
                            label-width="0px"
                            class="ms-content"
                        >
                            <el-form-item prop="username">
                                <el-input v-model="param.username" placeholder="username">
                                    <el-button slot="prepend" icon="el-icon-lx-people"></el-button>
                                </el-input>
                            </el-form-item>
                            <el-form-item prop="password">
                                <el-input
                                    type="password"
                                    placeholder="password"
                                    v-model="param.password"
                                    @keyup.enter.native="submitForm()"
                                >
                                    <el-button slot="prepend" icon="el-icon-lx-lock"></el-button>
                                </el-input>
                            </el-form-item>
                            <div class="login-btn">
                                <el-button type="primary" @click="submitForm()">登录</el-button>
                            </div>
                            <p class="login-tips">Tips : 用户名和密码随便填。</p>
                        </el-form>
                    </div>
                </div>
            </div>
            <div class="loginBox_bottom">2016 © 重庆联和纵道科技股份有限公司版权所有.</div>
        </form>
    </div>
</template>

<script>
import API from '../../api';
import md5 from 'js-md5';
export default {
    data: function() {
        return {
            param: {
                username: '4504030621006336',
                password: '111'
            },
            loading:false,
            rules: {
                username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
                password: [{ required: true, message: '请输入密码', trigger: 'blur' }]
            }
        };
    },
    mounted() {
        console.log(window.poIP);
    },
    methods: {
        submitForm() {
            var _this = this;
            this.$refs.login.validate(valid => {
                if (valid) {
                    var data = {
                        appId: 'lhzd',
                        username: '',
                        joinCode: _this.param.password,
                        userId: _this.param.username
                    };
                    _this.loading = true
                    API.login
                        .login(data)
                        .then(res => {
                            if (res) {
                                sessionStorage.setItem('accessToken', res.data.accessToken);
                                sessionStorage.setItem('userId',_this.param.username);
                                sessionStorage.setItem('roleIdList', JSON.stringify(res.data.fullRoles));
                                sessionStorage.setItem('roleId', res.data.fullRoles[0].roleId);
                                sessionStorage.setItem('roleName', res.data.fullRoles[0].name);

                                API.menu.menuList({ parentId: 0 }).then(ret => {
                                    sessionStorage.setItem('menuList', JSON.stringify(ret.data));
                                    _this.$router.push('/dashboard');
                                    _this.$message.success('登录成功');
                                });
                            }
                              _this.loading = false
                        })
                        .catch(err => {
                             _this.loading = false
                            console.log(err);
                        });
                } else {
                    this.$message.error('请输入账号和密码');
                    console.log('error submit!!');
                    return false;
                }
            });
        }
    }
};
</script>

<style scoped>
.login-wrap {
    position: relative;
    width: 100%;
    height: 100%;
    background-size: 100%;
}
.ms-title {
    width: 100%;
    line-height: 50px;
    text-align: center;
    font-size: 20px;
    color: #fff;
    border-bottom: 1px solid #ddd;
}
.ms-login {
    width: 350px;
    margin: -190px 0 0 -175px;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.3);
    overflow: hidden;
}
.ms-content {
    padding: 30px 30px;
}
.login-btn {
    text-align: center;
}
.login-btn button {
    width: 100%;
    height: 36px;
    margin-bottom: 10px;
}
.login-tips {
    font-size: 12px;
    line-height: 30px;
    color: #fff;
}
.header {
    width: 100%;
    height: 80px;
    background: #ffffff;
    top: 0px;
    left: 0px;
    z-index: 999;
    position: fixed;
    z-index: 3000;
}
.top {
    width: 1200px;
    height: 80px;
    line-height: 80px;
    margin: 0 auto;
    font-size: 12px;
    color: #333;
}
.logo {
    width: 30%;
    height: 60px;
    float: left;
    margin: 15px 5% 10px 2%;
}
.navbox {
    width: 50%;
    height: 80px;
    float: left;
    color: #666;
}
.navbox a {
    width: 30%;
    _width: 80px;
    height: 80px;
    line-height: 80px;
    display: block;
    float: right;
    font-size: 16px;
    text-align: center;
    color: #666;
    text-decoration: none;
}
.navbox a:hover {
    color: #333;
}
*:focus {
    outline: none;
}
.loginBox {
    background: #f8f8f8 url('../../assets/img/login-bg.jpg') no-repeat 30% 45%;
    height: 50%;
    padding-top: 26%;
    padding-bottom: 10%;
    padding-left: 5%;
    color: #ffffff;
    overflow: hidden;
}
.loginBox_title {
    text-align: center;
    font-size: 30px;
    margin-bottom: 10px;
}
.loginbox_bg {
    width: 1200px;
    margin: 0 auto;
}
.loginBox_left {
    width: 465px;
    float: left;
    padding-left: 50px;
}
.loginBox_content {
    width: 380px;
    color: #888;
    padding: 5px;
    animation: loginBox_content 1s 1;
    float: left;
}
.pic_loin {
    width: 150px;
    margin: 40px auto;
    animation: loginBox_content 1s 1;
}
.loginBox_content_t {
    background: #fff;
    min-height: 30px;
}
.tex {
    padding: 15px 50px 10px 60px;
    border-bottom: 1px solid #eee;
    color: #3cf;
    font-size: 18px;
}
.tex span {
    font-size: 12px;
    margin-left: 5px;
}
.loginBox_content_t1 {
    text-align: right;
    background-color: #ffe4d8;
    margin-top: 20px;
    margin-left: 35px;
    width: 300px;
    padding: 0px 5px;
    line-height: 30px;
    float: left;
    display: none;
}
.loginBox_content_c {
    padding: 10px 0px 20px 0px;
    border-radius: 0px 0px 5px 5px;
    background: #ffffff;
}
.loginBox_content_c_div {
    margin: 10px 23px;
    text-align: center;
}
.input {
    width: 220px;
    border: 1px solid #eeeeee;
    background: #f3f3f3;
    line-height: 35px;
    height: 35px;
    padding: 0px 5px;
    padding-left: 5px;
    margin-left: 35px;
    font-size: 14px;
}
.input:hover {
    border: 1px solid #c4d5e9;
    border-spacing: inherit;
}
input:-webkit-autofill {
    -webkit-box-shadow: 0 0 0px 1000px white inset;
}
.inputSub {
    width: 34%;
    outline: none;
    background: #4bacea;
    border: none;
    border-bottom: 1px solid #4098d1;
    border-radius: 3px;
    cursor: pointer;
    line-height: 30px;
    font-size: 14px;
    color: #fff;
    font-family: 'Microsoft YaHei';
    margin-left: 30px;
    margin-right: 4px;
}
.inputSub:hover {
    background: #4da2dc;
    border-bottom: 1px solid #3a8bbf;
}
.inputSub1 {
    width: 34%;
    outline: none;
    background: #f8f8f8;
    border: 1px solid #dadada;
    border-bottom: 1px solid #dadada;
    border-radius: 3px;
    cursor: pointer;
    line-height: 30px;
    font-size: 14px;
    color: #7d99af;
    font-family: 'Microsoft YaHei';
}
.inputSub1:hover {
    background: #eeeeee;
}
.loginBox_bottom {
    width: 1200px;
    margin: 0 auto;
    text-align: center;
    color: #999;
    margin-top: 20px;
}
.loginBox_content_b {
    width: 98%;
    margin: 0px auto;
    height: 8px;
    border-radius: 0px 0px 5px 5px;
    background: #f4f4f4;
}
.box_bg {
    margin-top: -2px;
}
.footBtns {
    text-align: center;
    padding: 50px 0px;
}
.footBtns a {
    border-radius: 5px;
    padding: 10px 50px;
    margin: 20px;
    border: 1px solid #fff;
    color: #fff;
    text-decoration: none;
}
.footBtns a:hover {
    background: #000;
}
#ajaxText {
    color: #ff6776;
    float: left;
}
#closeBtn {
    cursor: pointer;
    color: #fff;
    background-color: #fa6f1b;
    padding: 0px 5px;
    border-radius: 10px;
    font-family: Arial;
}
.inputImg {
    position: absolute;
    margin-top: 10px;
    margin-left: 7px;
}
</style>